package com.yswee.mallnavi.view.info;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yswee.framework.utils.ViewInject;
import com.yswee.framework.widget.clickedtab.ClickedTabBar;
import com.yswee.mallnavi.R;


/***
 * TabBar
 */
public class TabBar extends ClickedTabBar {

    @ViewInject
    private ImageView imglogo;
    @ViewInject
    private View btnbackhome;

    public TabBar(Context context) {
        super(context);
    }

    public TabBar(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.view_info_tabbar;
    }

    @Override
    protected void onBindListener() {
        super.onBindListener();
        btnbackhome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((Activity) mContext).finish();
            }
        });
    }

    @Override
    protected int[] getChildViewResIDs() {
        return new int[] {
                R.id.llnavi,
                R.id.llpark,
                R.id.llmember,
                R.id.llintro,
                R.id.llbrand,
                R.id.llfood,
                R.id.llcoupon
        };
    }

    @SuppressWarnings("deprecation")
    @Override
    protected void focusChildView(int index, View v) {
        LinearLayout llcontainer = (LinearLayout) v;
        ImageView imgicon = (ImageView) llcontainer.getChildAt(0);
        TextView tvnamecn = null;
        TextView tvnameen = null;
        if (llcontainer.getChildCount() == 3) {
            tvnamecn = (TextView) llcontainer.getChildAt(1);
            tvnameen = (TextView) llcontainer.getChildAt(2);
        } else {
            LinearLayout llcontainer_in = (LinearLayout) llcontainer.getChildAt(1);
            tvnamecn = (TextView) llcontainer_in.getChildAt(0);
            tvnameen = (TextView) llcontainer_in.getChildAt(1);
        }
        int resid = 0, logoResId = R.color.transparent;
        switch(index) {
            case 0:
                resid = R.drawable.tabbar_navi_select;
                break;
            case 1:
                resid = R.drawable.tabbar_park_select;
                logoResId = R.drawable.icon_park;
                break;
            case 2:
                resid = R.drawable.tabbar_member_select;
                logoResId = R.drawable.icon_member;
                break;
            case 3:
                resid = R.drawable.tabbar_intro_select;
                logoResId = R.drawable.icon_intro;
                break;
            case 4:
                resid = R.drawable.tabbar_brand_select;
                logoResId = R.drawable.icon_brand;
                break;
            case 5:
                resid = R.drawable.tabbar_food_select;
                logoResId = R.drawable.icon_food;
                break;
            case 6:
                resid = R.drawable.tabbar_coupon_select;
                logoResId = R.drawable.icon_coupon;
                break;
        }
        imgicon.setImageResource(resid);
        imglogo.setImageResource(logoResId);
        tvnamecn.setTextColor(getResources().getColor(R.color.widget_tabbar_focus_fg));
        tvnameen.setTextColor(getResources().getColor(R.color.widget_tabbar_focus_fg));
        llcontainer.setBackgroundResource(R.color.widget_tabbar_focus_bg);
    }

    @SuppressWarnings("deprecation")
    @Override
    protected void unfocusChildView(int index, View v) {
        LinearLayout llcontainer = (LinearLayout) v;
        ImageView imgicon = (ImageView) llcontainer.getChildAt(0);
        TextView tvnamecn = null;
        TextView tvnameen = null;
        if (llcontainer.getChildCount() == 3) {
            tvnamecn = (TextView) llcontainer.getChildAt(1);
            tvnameen = (TextView) llcontainer.getChildAt(2);
        } else {
            LinearLayout llcontainer_in = (LinearLayout) llcontainer.getChildAt(1);
            tvnamecn = (TextView) llcontainer_in.getChildAt(0);
            tvnameen = (TextView) llcontainer_in.getChildAt(1);
        }
        int resid = 0;
        switch(index) {
            case 0:
                resid = R.drawable.tabbar_navi_normal;
                break;
            case 1:
                resid = R.drawable.tabbar_park_normal;
                break;
            case 2:
                resid = R.drawable.tabbar_member_normal;
                break;
            case 3:
                resid = R.drawable.tabbar_intro_normal;
                break;
            case 4:
                resid = R.drawable.tabbar_brand_normal;
                break;
            case 5:
                resid = R.drawable.tabbar_food_normal;
                break;
            case 6:
                resid = R.drawable.tabbar_coupon_normal;
                break;
        }
        imgicon.setImageResource(resid);
        tvnamecn.setTextColor(getResources().getColor(R.color.widget_tabbar_unfocus_fg));
        tvnameen.setTextColor(getResources().getColor(R.color.widget_tabbar_unfocus_fg));
        llcontainer.setBackgroundResource(R.color.widget_tabbar_unfocus_bg);
    }

    public void setLogoResId(int resId) {
        imglogo.setImageResource(resId);
    }

}